var globalApp = getApp(), dataProvider = require("../../provider/dataApi.js");

require("../../provider/pipe.js");

Page({
    data: {
        statusBarHeight: "",
        titleBarHeight: "",
        typeList: [],
        total: 0,
        dayHaveErr: 2,
        allHaveErr: 2
    },
    onLoad: function(options) {
        this.setData({
            statusBarHeight: globalApp.globalData.statusBarHeight,
            titleBarHeight: globalApp.globalData.titleBarHeight
        });
    },
    goToday: function() {
        globalApp.globalData.op = "todayerr_question", wx.getStorageSync("uid") ? 2 == this.data.dayHaveErr ? wx.showToast({
            icon: "none",
            title: "今日无错题~"
        }) : wx.navigateTo({
            url: "../practice/practice"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goAll: function() {
        globalApp.globalData.op = "allerr_question", wx.getStorageSync("uid") ? 2 == this.data.allHaveErr ? wx.showToast({
            icon: "none",
            title: "暂无错题~"
        }) : wx.navigateTo({
            url: "../practice/practice"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goType: function(event) {
        wx.getStorageSync("uid") ? (globalApp.globalData.op = "geterr_bytype", globalApp.globalData.id = event.currentTarget.id, 
        wx.navigateTo({
            url: "../practice/practice"
        })) : wx.navigateTo({
            url: "../login/login"
        });
    },
    bindWechat: function() {
        wx.showModal({
            title: "绑定微信",
            content: "需要绑定微信才能进行下一步操作,点击确定去绑定",
            showCancel: !0,
            confirmText: "确定",
            success: function(result) {
                console.log(result), result.confirm && wx.navigateTo({
                    url: "../bindWechat/bindWechat"
                });
            }
        });
    },
    onShow: function() {
        this.getUserInfo(), this.myErrList();
    },
    getUserInfo: function() {
        dataProvider.userinfo({
            uid: wx.getStorageSync("uid"),
            op: "getinfo"
        }).then(function(response) {
            console.log(response), wx.setStorageSync("userinfo", response.data.info), wx.setStorageSync("http", response.data.http);
        }).catch(function(error) {
            console.log(error);
        });
    },
    myErrList: function() {
        var self = this;
        dataProvider.myerrList({
            uid: wx.getStorageSync("uid")
        }).then(function(response) {
            console.log(response), self.setData({
                total: response.data.total,
                typeList: response.data.typelist,
                dayHaveErr: response.data.day_have_err,
                allHaveErr: response.data.all_have_err
            }), console.log(response.data.total);
        }).catch(function(error) {
            console.log(error);
        });
    },
    onShareAppMessage: function() {}
});